﻿<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>订单</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="~/layui-v2.4.5/layui/css/layui.css" rel="stylesheet" />
	<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

	<table class="layui-hide" id="test" lay-filter="test"></table>

	<script type="text/html" id="toolbarDemo">

		<div class=" layui-container">

			<div class="layui-row">
				<div class="layui-col-xs3">
					<div class="grid-demo grid-demo-bg1">
						<div class="layui-btn-container">
							<button class="layui-btn layui-btn-sm" lay-event="queryWaitList">待处理</button>
							<button class="layui-btn layui-btn-sm" lay-event="queryGatherOrderList">已收件</button>
							<button class="layui-btn layui-btn-sm" lay-event="queryRevocation">已撤销</button>
							<button class="layui-btn layui-btn-sm" lay-event="queryCustomerRevocation">客户取消</button>
							@*<button class="layui-btn layui-btn-sm" lay-event="gatherOrderList">批量收件</button>
		<button class="layui-btn layui-btn-sm" lay-event="revocation">撤销订单</button>*@
							@*<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>*@
						</div>
					</div>
				</div>
				<div class="layui-col-xs9">
					<div class="grid-demo">
						地址:	<input type="text" name="address" id="address" value="">
						电话:	<input type="text" name="mobile"  id="mobile"  value="">
						姓名:	<input type="text" name="username" id="username"value="">
						<button class="layui-btn layui-btn-sm" lay-event="queryOrderList">查询</button>

					</div>
				</div>
			</div>


		</div>
	</script>

	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="gather">收件</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="revocation">撤销</a>
	</script>

	<script src="~/layui-v2.4.5/layui/layui.all.js" charset="utf-8"></script>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

	<script> 
		var secretKey = '48240d05a398bcf2';
		layui.use(['table','jquery'], function () {
			var table = layui.table;
			var $ = layui.$;//重点处
			table.render({
				elem: '#test'
				, url: '/BmobOrder/pagelist'
				, toolbar: '#toolbarDemo'
				, title: '订单'  
				 , id: 'testReload'
				, cols: [[
					{ type: 'checkbox', fixed: 'left' }
					, { field: 'objectId', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true }

					, { field: 'ReceiveAddress', minWidth: 150, title: '地址', sort: true }
					, { field: 'ProductName', title: '寄托物'  }

					, { field: 'ReceiveMobile', title: '电话'  }
					, { field: 'ReceiveName', title: '收件人'  }
					, { field: 'WeightGram', title: '重量' ,sort: true }
					, {
						field: 'Status', title: '状态', width: 150, templet: function (res) {
							if (res.Status == 0) return "待接单";
							if (res.Status == 1) return "已收件";
							if (res.Status == 2) return "已派件";
							if (res.Status == 3) return "已退单(撤销)";
							if (res.Status == 4) return "客户取消";
							return res.Status
						}
					}
					, { field: 'createdAt', width: 165, title: '下单时间', sort: true }
					, { field: 'updatedAt', width: 165, title: '更新时间', sort: true }
					, { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }

				]]
				, page: true
			});

			//头工具栏事件
			table.on('toolbar(test)', function (obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				switch (obj.event) {
					case 'queryWaitList':
						var data = checkStatus.data;

						//layer.alert(JSON.stringify(data));
						//执行重载
						table.reload('testReload', {
							//page: {
							//	curr: 1 //重新从第 1 页开始
							//}	,
						 where: {
								key: {
									status: 0
								}
							}
						});

						break;
					case 'queryGatherOrderList': 
						var data = checkStatus.data;
						table.reload('testReload', {
							//page: {
							//	curr: 1 //重新从第 1 页开始
							//},
							where: {
								key: {
									status: 1
								}
							}
						});
						break;
					case 'queryOrderList'://按地址 姓名 电话 查询
						var data = checkStatus.data;
						table.reload('testReload', {
							//page: {
							//	curr: 1 //重新从第 1 页开始
							//},
							 where: {
								key: {
									name: $("#username").val(),
									mobile: $("#mobile").val(),
									address: $("#address").val(),
								}
							}
						});
						break;
					case 'queryRevocation':
						//layer.msg(checkStatus.isAll ? '全选' : '未全选');
						//执行重载
						table.reload('testReload', {
							//page: {
							//	curr: 1 //重新从第 1 页开始
							//}	,
							where: {
								key: {
									status: 3
								}
							}
						});
						break;
					case 'queryCustomerRevocation':
						//layer.msg(checkStatus.isAll ? '全选' : '未全选');
						//执行重载
						table.reload('testReload', {
							//page: {
							//	curr: 1 //重新从第 1 页开始
							//}	,
							where: {
								key: {
									status: 0
								}
							}
						});
						break;
				};
			});

			//监听行工具事件
			table.on('tool(test)', function (obj) {
				var data = obj.data;
				//console.log(obj)
				if (obj.event === 'gather') {
					layer.prompt({
						formType: 2
						, value: data.email
					}, function (value, index) {
						$.get("http://cloud.bmob.cn/" + secretKey + "/changeStatus?id=" + data.objectId + "&status=1" + "&statusNode=exp", function (res) {
							layer.close(index);
							console.log(res);
							obj.update({
								status: 1
							});
						});

					})					 
				} else if (obj.event === 'revocation') {
					layer.confirm('真的撤销么', function (index) {
						$.get("http://cloud.bmob.cn/" + secretKey + "/changeStatus?id=" + data.objectId + "&status=3", function (res) {
							layer.close(index);
							console.log(res);
						});
						//obj.del();

					});


				}
			});
		});
		
	</script>

</body>
</html>